var Query = RichBase.extend({
	statics : {
		currentPage : 0,
		last : "",
		queryState : {
			loading : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">加载数据...</p><img src="images/other/loading_1.gif" alt="" /></li>',
			empty : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:150px;">没有数据...</p></li>',
			fail : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求失败...</p></li>',
			unlogin : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">登录过期，请重新登录...</p></li>',
			timeout : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">网络请求超时...</p></li>',
			serverError : '<li class="loading" style="text-align:center; line-height:1; height:400px;"><p style="color:#aeaeae; font-size:12px; padding-top:300px;">请求出错...</p></li>'
		},
		isObjEmpty : function(obj){
			for(var i in obj){
				return false;
			}
			return true;
		}
	}, 
	EVENTS : {
		"click" : {
			"#pagenavW .pageBtn" : "onPrevNextClick"
		}
	},
	init : function(opt){
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
	},
	onPrevNextClick : function(that,e){
		var tarBtn = $(e.currentTarget);
		if($("#prevPageBtn").attr("data-first")!=0){
			that.prevBtn.removeClass("disable");
		}else{
			that.prevBtn.addClass("disable");
		}
		$(".page_num_").val("");
		if(tarBtn.hasClass("disable")) return false;
		var type = $(".page_sub").attr("data");
		var curPage = $(".page_num_").val();
		var toPage = tarBtn.hasClass("prevBtn") ? (curPage-1) : (curPage+1);
		var all = $(".nextBtn").attr("total");
		var aid = $(".credit_active").attr("aid");
		var mid = Number($("#prevPageBtn").attr("data-mid"));
		var last_ = Number($("#prevPageBtn").attr("data-last"));
		var first_ = Number($("#prevPageBtn").attr("data-first"));
		var total_ = Number($("#nextPageBtn").attr("total"));
		var type = Number($(".listBox").attr("data"));
		var search_title = $("#search_title").val();
		if(tarBtn.hasClass("prevBtn")){
				that.nextBtn.removeClass("disable");
				if(first_=="0"){
					that.prevBtn.addClass("disable");
					return false;
				}
				else{
					if(type=="0"){
						qQuery.query({
							last : first_,
							status : "0",
							title : search_title
						})	
					}else if(type=="1"){
						qQuery.query({
							last : first_,
							status : "1",
							title : search_title
						})
					}else{
						qQuery.query({
							last : first_,
							status : "3",
							title : search_title
						})
						
					}	
				}

			}else{
				that.prevBtn.removeClass("disable");
				if(last_<=total_){
					if(type=="0"){
						qQuery.query({
							last : last_,
							status : "0",
							title : search_title
						})	
					}else if(type=="1"){
						qQuery.query({
							last : last_,
							status : "1",
							title : search_title
						})
					}else{
						qQuery.query({
							last : last_,
							status : "2",
							title : search_title
						})
					}	
				}else{
					that.nextBtn.addClass("disable");
				}
			}
			
	},
	query : function(opt){
		var tyepp = $(".credit_active").attr("data");
		var that = this;
		var opt = opt || {};
		var pageSize = opt.pageSize || 15;
		var last = opt.last || "1";
		var title = opt.title;
		var ttimeout = opt.ttimeout || 20 * 60 * 1000;
		var listUl = $("#mlistUl");
		var ty = opt.status;
		var pagenavW = $("#pagenavW");
		var status = this.statics.queryState;
		var data_a = {
				currentPage : last,
				dname : title,
				status : ty,
				action : "list"
			};
			PFT.Ajax({
				url : "tao_manage.html",
				type : "GET",
				dataType : "json",
				data : data_a,
				loading : function(){
					listUl.html(status["loading"]);
					pagenavW.hide();
					},
				removeLoading : function(res){
					that.statics.last = "";
					that.statics.currentPage += 1;
					listUl.html("");
					pagenavW.show();
				}
			},function(res){
				var lists = res.list;
					if(!that.statics.isObjEmpty(lists)){
						that.buildHtml(res);
					}else{
						listUl.html(status["empty"]);
						$("#pagenavW").hide();
					}
			})
	},
	buildHtml : function(res){
		var that = this;
		var lists = res.list;
		var str = "";
		var last = res.last;
		var data = lists;
		var total = res.total;
		var totalPage = res.totalPage || "0";
		var currentPage = res.currentPage;
		var cur = Number(currentPage)
		$(".nextBtn").attr("total",totalPage);
		$("#prevPageBtn").attr("data-mid",cur);
		$("#prevPageBtn").attr("data-last",cur+1);
		$("#prevPageBtn").attr("data-first",cur-1);
		$(".search_titile").attr("time",totalPage)
		str +=   '<thead>';
		str +=   '	<tr>';
        str +=   '      <th class="setThAlign">单位名称</th>';
        str +=   '      <th class="w140">申请时间</th>';
        str +=   '      <th class="w90">账号</th>';
        str +=   '      <th class="w90">电话</th>';
        str +=   '      <th class="w180">淘宝账户</th>';
        str +=   '      <th class="w80">操作</th>';                  
        str +=   '  </tr>';
		str +=   '</thead>';
		str +=   '<tbody>';
		for(var i in data){
			str +=   '<tr>';
            str +=   '    <td class="setTdAlign">'+data[i]["dname"]+'</td>';
            str +=   '    <td>'+data[i]["createtime"]+'</td>';
            str +=   '    <td>'+data[i]["account"]+'</td>';
            str +=   '    <td>'+data[i]["mobile"]+'</td>';
            str +=   '    <td class="setColor setTxt">'+data[i]["seller_nick"]+'</td>';
            //str +=   '    <td class="colorBlue" mid="'+data[i]["mid"]+'" tid="'+data[i]["tid"]+'" status="'+data[i]["status"]+'">';
            str +=   '    <td class="colorBlue" mid="'+data[i]["mid"]+'" tid="'+data[i]["tid"]+'" status="'+data[i]["status"]+'">';
			str +=   '      <a class="vefify statics" mid="'+data[i]["mid"]+'" tid="'+data[i]["tid"]+'" data="">通过审核</a></br>';
			str +=   '		<a class="cansel statics" mid="'+data[i]["mid"]+'" tid="'+data[i]["tid"]+'" style="color:red;" data="">取消绑定</a>';
			str +=   '    </td>';
            str +=   '</tr>';
		}
		str +=   '</tbody>';
		$("#mlistUl").html(str);
		//$("html,body").animate({"scrollTop":0})
		$("#total_num").text("共"+totalPage+"页");	
		$("#whichPageNum").text(currentPage);
		$("#total_all").text(+total+"条记录");
		$(".colorBlue").each(function(e){  //status 1   已审核     status  0 未审核
			var tarBtn = $(e.currentTarget);
			if(Number(($(this).attr("status")))=="0"){
				$(this).find(".cansel").text("拒绝审核");
				$(this).find(".vefify").attr("data","1");   //data 1 确定审核    2  拒绝审核  0 取消审核
				$(this).find(".cansel").attr("data","2");
			}else{
				$(this).find(".vefify").text("取消绑定");
				$(this).find(".vefify").attr("data","0");
				$(this).find(".vefify").css("color","red");
				$(this).find(".cansel").remove();
			}
		})
	}
});
var qQuery = new Query({container:$(".rtWrap")});
var Main = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			".all_tao" : "all_tao",
			".can_tao" : "can_tao",
			".re_tao" : "re_tao",
			".page_sub" : "bl",
			".cancelBtn" : "cancelBtn"  //淘宝核销
		}},
	init : function(opt){
		var that = this;
		this.container = opt.container;
		this.prevBtn = $("#prevPageBtn");
		this.nextBtn = $("#nextPageBtn");
		qQuery.query({

		});
	},
	cancelBtn : function(){
		var taobao_oid = $(".taobao_oid").val();
		if(!taobao_oid || !PFT_GLOBAL.U.istiveNum(taobao_oid)){
			$(".taobao_oid").val("");
			PFT_GLOBAL.U.Alert("fail",'<p style="width:440px">抱歉输入有误,请重新输入16位淘宝订单号</p>');
			return false;
		}
		var data_oid = {
				taobao_oid : taobao_oid
			};
		PFT.Ajax({
			url : "abc/consume.php",
			type : "POST",
			dataType : "json",
			data : data_oid
		},function(res){
			if(res.status=="success"){
				//PFT_GLOBAL.U.Alert("success",'<p style="width:240px">'+res.msg+'</p>');
				$(".successMsg").text(res.msg);
				$(".successMsg").css("color","#3DBA3F");
				setTimeout(function () { 
					$(".successMsg").text("");
				}, 1200);
			}else{
				//PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">'+res.msg+'</p>');
				$(".successMsg").text(res.msg);
				$(".successMsg").css("color","red"); 
				$(".taobao_oid").val("");
				setTimeout(function () { 
					$(".successMsg").text("");
				}, 1200);
			}
			
		})
		
		
	},
	bl : function(){
		var page_size = Number($(".page_num_").val());
		var all = Number($(".nextBtn").attr("total"));
		var type = Number($(".listBox").attr("data"));
		var search_title = $("#search_title").val();
		var cur = Number($(".page_num_").val());
		$(".page_num_").val("");
		if(page_size<=all){
			if(type=="0"){
				qQuery.query({
					status : "0",
					last : cur,
					title : search_title
				});
			}else if(type=="1"){
				qQuery.query({
					status : "1",
					last : cur,
					title : search_title
				});
			}else{
				qQuery.query({
					status : "2",
					last : cur,
					title : search_title
				});
			}
		}
		else{
			return false;
		}
		
		
	},
	all_tao : function(that,e){
			var target = $(e.currentTarget);
			var search_title = $("#search_title").val();
			$(".listBox").attr("data","0");
				qQuery.query({
					title : search_title
				})
			$("#mlistUl_wrapper").hide();
			$("#mlistUl_a_wrapper").show();
			target.addClass("active");
			$(".can_tao").removeClass("active");
			$(".re_tao").removeClass("active");
	},
	can_tao : function(that,e){
			var search_title = $("#search_title").val();
			var target = $(e.currentTarget);
			$(".listBox").attr("data","1");
			qQuery.query({
				status : "1",
				title : search_title
			 })
			$(".all_tao").removeClass("active");
			$(".re_tao").removeClass("active");
			target.addClass("active");
			$(".pub_top_left").attr("data_li","0");

	},
	re_tao : function(that,e){
			var search_title = $("#search_title").val();
			var target = $(e.currentTarget);
			$(".listBox").attr("data","2");
			qQuery.query({
				status : "2",
				title : search_title
			 })
			$(".all_tao").removeClass("active");
			$(".can_tao").removeClass("active");
			target.addClass("active");
	}

});
var search = RichBase.extend({
	statics : {},
	EVENTS : {
		"click" : {
			".searchBtn" : "search_sub",
			".del_x" : "del"
		}},
	init : function(opt){
		var that = this;
	},
	del : function(){
		var status = $(".listBox").attr("data");
		$("#search_title").val("");
		qQuery.query({
			status : status
		});
		
	},
	search_sub :function(){ 
		var search_title = $("#search_title").val();
		var status = $(".listBox").attr("data");
		if(!search_title){
			PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">未输入单位名称</p>');
			return false
		}else{
			if($(".pub_top_left").attr("data_li")=="2"){
				qQuery.query({
					title : search_title,
					status : status
				});
			}else{
				qQuery.query({
					title : search_title,
					status : status
				});
			}
		}
	}

});
new Main({container:$(".rtWrap")});
new search({container:$(".rtWrap")});

$(".statics").live("click",function(){
	var mid = Number($(this).attr("mid"));
	var tid = Number($(this).attr("tid"));
	var status = Number($(this).attr("data"));
	if(status=="2"){
		var bh = $("html").height();   
		var bw = $("html").width();      
		$("#mask").css({ height:bh, width:bw, display:"block" });
		$(".tao_mask").show();  //打开弹出层
		$("#input_txt").text("店铺名称有误，绑定失败！请确认并重新提交。");
		$(".btn_submit").attr("mid",mid);
		$(".btn_submit").attr("tid",tid);
	}else{
		if(status=="0"){
			if(confirm("确定要解除绑定吗?")){
				var data = {
					uid : mid,
					log_id : tid,
					status : status,
					action : "applyBindtb"
				};
				PFT.Ajax({
					url : "call/jh_mem.php",
					type : "POST",
					dataType : "json",
					data : data
				},function(res){
					if(res.s=="success"){
						PFT_GLOBAL.U.Alert("success",'<p style="width:240px">'+res.msg+'</p>');
						if(status=="0"){
							
								var search_title = $("#search_title").val();
								var top_type = Number($(".listBox").attr("data"));
								if(top_type=="0"){
									$(".all_tao").addClass("active");
									$(".can_tao").removeClass("active");
									$(".re_tao").removeClass("active");
									$(".listBox").attr("data","0");
									qQuery.query({
										title : search_title
									 })
								}else{
									$(".all_tao").removeClass("active");
									$(".can_tao").addClass("active");
									$(".re_tao").removeClass("active");
									$(".listBox").attr("data","1");
									qQuery.query({
										status : "1",
										title : search_title
									 })
								}
							
						}else{
							$(".all_tao").removeClass("active");
							$(".can_tao").removeClass("active");
							$(".re_tao").addClass("active");
							var search_title = $("#search_title").val();
							$(".listBox").attr("data","2");
							qQuery.query({
								status : "2",
								title : search_title
							 })
						}
					}else{
						PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">'+res.msg+'</p>');
					}
					
				})
			
			}
			
		}else{
			var data = {
				uid : mid,
				log_id : tid,
				status : status,
				action : "applyBindtb"
				};
		PFT.Ajax({
			url : "call/jh_mem.php",
			type : "POST",
			dataType : "json",
			data : data
		},function(res){
			if(res.s=="success"){
				PFT_GLOBAL.U.Alert("success",'<p style="width:240px">'+res.msg+'</p>');
				if(status=="0"){
					
						var search_title = $("#search_title").val();
						var top_type = Number($(".listBox").attr("data"));
						if(top_type=="0"){
							$(".all_tao").addClass("active");
							$(".can_tao").removeClass("active");
							$(".re_tao").removeClass("active");
							$(".listBox").attr("data","0");
							qQuery.query({
								title : search_title
							 })
						}else{
							$(".all_tao").removeClass("active");
							$(".can_tao").addClass("active");
							$(".re_tao").removeClass("active");
							$(".listBox").attr("data","1");
							qQuery.query({
								status : "1",
								title : search_title
							 })
						}
					
				}else{
					$(".all_tao").removeClass("active");
					$(".can_tao").removeClass("active");
					$(".re_tao").addClass("active");
					var search_title = $("#search_title").val();
					$(".listBox").attr("data","2");
					qQuery.query({
						status : "2",
						title : search_title
					 })
				}
			}else{
				PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">'+res.msg+'</p>');
			}
			
		})
			
			
		}
		
	}
})
$(".tao_mask").on('click', '.btn_submit', function(){
		var url = "call/jh_mem.php";
		var msg = $("#input_txt").val();
		var mid =$(".btn_submit").attr("mid");
		var tid = $(".btn_submit").attr("tid");
		var postData ={
				uid : mid,
				log_id : tid,
				status : "2",
				msg : msg,
				action : "applyBindtb"
			}
		$.ajax({
			type:'POST',url: url,data: postData, dataType:'json'
		}).done(function(res) {
			if(res.s=="success"){
				PFT_GLOBAL.U.Alert("success",'<p style="width:240px">'+res.msg+'</p>');
				$("#mask,.tao_mask").hide(); 
				var search_title = $("#search_title").val();
				$(".listBox").attr("data","2");
				qQuery.query({
					status : "2",
					title : search_title
				 })
				$(".all_tao").removeClass("active");
				$(".can_tao").removeClass("active");
				$(".re_tao").addClass("active");
			}else{
				PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">'+res.msg+'</p>');
			}
		})
})
function closeBg() { 
	$("#mask,.tao_mask").hide(); 
} 

